

//var ip="203.195.214.80";
var ip="127.0.0.1";
//var ip="203.195.189.85";

function connSocketIOUpload(openId){
	
	var socket = io.connect(ip+":6380");

	socket.on('conn', function (data) {

	 var postdata = {

		   'c_id'   : openId,     //用户id

	 };

	 socket.emit('pedometerUploadLogin', postdata);
//
	});
	
	socket.on('receivePedometerUpload', function (data,fn) {
		upload(data.type);		

	});
}

//var uploadTime=null;
function upload(type){
	if(type==0){
		document.getElementById("pedometer_upload").style.display="block";

	}else{
		
		
		var pedometer_upload = document.getElementById("pedometer_upload");
		if(pedometer_upload.style.display=="block"){
			pedometer_upload.style.display="none";
		}else{
			pedometer_upload.style.display="block";
			setTimeout(clearUpload, 3000);
		}
		

	}
}

//function loadPedometer(){
//	drawCircle_pedometer2("canvas_pedometer2");
//}

function clearUpload(){
	document.getElementById("pedometer_upload").style.display="none";
	ajaxLoadPedometerRecord();
}


//弹出添加目标步数
function alertWin(step){
	if(step>1000){
		document.getElementById("alert_value_reduce").style.display = "block";
	}else{
		document.getElementById("alert_value_reduce").style.display = "none";
	}
	if(step>=144000){
		document.getElementById("alert_value_plus").style.display = "none";
	}else{
		document.getElementById("alert_value_plus").style.display = "block";
	}
	var myAlert = document.getElementById("alert_pedometerGoal");
	//document.getElementById("alert_pedometerGoal_date").value=getNowTime();//添加框时间
	myAlert.style.display = "block";
	myAlert.style.position="absolute";
	var mybg = document.createElement("div");
	mybg.setAttribute("id","alert_bg");
	mybg.style.background = "#000";

	mybg.style.width = "100%";
	mybg.style.height = document.body.scrollHeight+"px";
	mybg.style.position = "fixed";
	mybg.style.overflow="hidden";
	mybg.style.top = "0";
	mybg.style.left = "0";
	mybg.style.zIndex = "3000";
	mybg.style.opacity = "0.3";
//	mybg.setAttribute("class","bg");
//	mybg.style.filter = "Alpha(opacity=30)";
	
	document.body.appendChild(mybg);
	document.body.style.overflow = "hidden";
	
}
function value_change(){
	var step=document.getElementById("alert_pedometerGoal_value").innerHTML;
	var height = document.getElementById("hidden_memberHeight").value/100;
	var weight = document.getElementById("hidden_memberWeight").value;
	//获取目标热量消耗
 	var calories_text =  Math.round(getCalories(weight,step));
	//目标距离
 	var td_text =  Math.round(getTD(height,step));
 	
	var distance=step*0.4/1000;
	var calories=step/30;
//	var walkingTime=distance/5;
	var walkingTime=step/100/60;
	var runningTime=distance/10;
	if(distance!=0){
		var str=parseFloat(distance).toFixed(1);
		var point=str.indexOf(".");
		var str1=str.substring(point+1, str.length);
		if(str1=="0"){
			str=str.substring(0,point);
		}
		distance=str;
	}
	if(calories!=0){
		var str=parseFloat(calories).toFixed(1);
		var point=str.indexOf(".");
		var str1=str.substring(point+1, str.length);
		if(str1=="0"){
			str=str.substring(0,point);
		}
		calories=str;
	}
	var wth=0;
	var wtm=0;
	if(walkingTime!=0){
		var str=parseFloat(walkingTime).toFixed(2);
		var point=str.indexOf(".");
		wth=str.substring(0,point);
		var str1=str.substring(point+1, str.length);
		wtm=str1*0.6;
		wtm=parseFloat(wtm).toFixed(0);
		//walkingTime=str;
	}

	//图标切换
	if(step<5999){
		document.getElementById("alert_pedometerGoal_level_ico").src =ctx+"/weixin/v1/img/foot_fail.png";
	}else if(step<9999){
		document.getElementById("alert_pedometerGoal_level_ico").src =ctx+"/weixin/v1/img/foot_pass.png";
	}else{
		document.getElementById("alert_pedometerGoal_level_ico").src =ctx+"/weixin/v1/img/foot_great.png";
	}
	

	//document.getElementById("alert_pedometerGoal_distance").innerHTML=distance;
	document.getElementById("alert_pedometerGoal_walkingTime_h").innerHTML=wth+"小时";		
	document.getElementById("alert_pedometerGoal_walkingTime_m").innerHTML=wtm+"分钟";
	if(wth<=0){
		document.getElementById("alert_pedometerGoal_walkingTime_h").innerHTML="";
	}
	if(wtm<=0){
		document.getElementById("alert_pedometerGoal_walkingTime_m").innerHTML="";
	}

	//alert("步数："+step+"里程："+distance+"卡路里："+calories+"步行时间："+walkingTime+"跑步时间："+runningTime);
	document.getElementById("alert_pedometerGoal_TD").innerHTML = td_text +"米";
	document.getElementById("alert_pedometerGoal_Calories").innerHTML = calories_text +"大卡";
	var textLength = document.getElementById("alert_pedometerGoal_text").innerHTML.length;
	if(textLength>230){
		document.getElementById("alert_pedometerGoal_text").className = "alert_pedometerGoal_text alert_pedometerGoal_text_long";
	}else{
		document.getElementById("alert_pedometerGoal_text").className = "alert_pedometerGoal_text";
	}
}

function pedometerGoal_plus(){
	var value=document.getElementById("alert_pedometerGoal_value").innerHTML;
	value=parseInt(value)+500;
	if(value>=144000){
		//隐藏+号
		document.getElementById("alert_value_plus").style.display = "none";
	}
	if(value>1000){
		//显示-号
		document.getElementById("alert_value_reduce").style.display = "block";
	}
	if(value>144000){
		pedometerGoal_stop();
		return;
	}
	document.getElementById("alert_pedometerGoal_value").innerHTML=value;
	value_change();
}
function pedometerGoal_reduce(){
	var value=document.getElementById("alert_pedometerGoal_value").innerHTML;
	value=parseInt(value)-500;
	if(value==1000){
		//隐藏-号
		document.getElementById("alert_value_reduce").style.display = "none";
	}
	if(value<144000){
		//显示+号
		document.getElementById("alert_value_plus").style.display = "block";
	}
	if(value<1000){
		pedometerGoal_stop();
		return;
	}
	document.getElementById("alert_pedometerGoal_value").innerHTML=value;
	value_change();
}
var timer;
function pedometerGoal_plus_loop(){
	clearTimeout(timer);
	var i=0;
	timer=setInterval(function(){
		i++;
		if(i>50){
			pedometerGoal_plus();
		}
	},10);
}
function pedometerGoal_reduce_loop(){
	clearTimeout(timer);
	var i=0;
	timer=setInterval(function(){
		i++;
		if(i>50){
			pedometerGoal_reduce();
		}
	},10);
}
function pedometerGoal_stop(){
	clearTimeout(timer);
}
//弹出框移除背景
function removeMybg(){
	if(se==0){
		return;
	}
	se=0;
	var mybg=document.getElementById("alert_bg");
	var myAlert = document.getElementById("alert_pedometerGoal");
	document.body.style.overflow = "visible";
	myAlert.style.display = "none";
	document.body.removeChild(mybg);
}

var start=1.5;
var end=1.5;

//画圆环
function drawCircle_pedometer(canvasId, circleAngle,type){
	var canvas = document.getElementById(canvasId);
	if (canvas.getContext) {
		var lineWidth = 16 * 2;
		var width = 220 * 2;
		var height = width;
		var shadowBlur = 5 * 2;
		var radius = (width)/2 -shadowBlur - lineWidth;
		var x = width/2;
		var y = height/2;
		canvas.width = width;
		canvas.height = height;
		var context = canvas.getContext('2d');
		context.clearRect(0,0,canvas.width,canvas.height);
		context.lineWidth = lineWidth;
		var endAngle=0*Math.PI;
		if(circleAngle>=100){
			endAngle=0.49*Math.PI;
		}else if(circleAngle>75){
			endAngle=(0.5-(100-circleAngle)*0.02)*Math.PI;
		}else{
			endAngle=(0.5+circleAngle*0.02)*Math.PI;
		}
		var startAngle=0.5*Math.PI;
		
		//白色背景
		context.strokeStyle = "#fff";
		context.lineCap = "round";
		context.shadowColor = "#ccc";
		context.shadowBlur = shadowBlur+1;
		context.shadowOffsetX = 0;
		context.shadowOffsetY = 0;
		context.beginPath();
		context.arc(x, y, radius, 0.5*Math.PI, 0.49*Math.PI, false);
		context.stroke();
		
		
		var linear = context.createLinearGradient(10,0,360,360); 
		linear.addColorStop(0,'#aaa'); 
		linear.addColorStop(0.5,'#f44444'); 
		linear.addColorStop(1,'red');
		
		context.strokeStyle = "#f7882d";
		context.beginPath();
		context.arc(x, y, radius, startAngle, endAngle, false);
		context.stroke();
		
		context.restore();

	}
}




//画上传数据中圆环
function drawCircle_pedometer2(canvasId){
	var canvas = document.getElementById(canvasId);
	if (canvas.getContext) {
		var lineWidth = 16 * 2;
		var width = 220 * 2;
		var height = width;
		var shadowBlur = 5 * 2;
		var radius = (width)/2 -shadowBlur - lineWidth;
		var x = width/2;
		var y = height/2;
		canvas.width = width;
		canvas.height = height;
		var context = canvas.getContext('2d');
		context.clearRect(0,0,canvas.width,canvas.height);
		context.lineWidth = lineWidth;
		
		//白色背景
		context.strokeStyle = "#fff";
		context.lineCap = "round";
		context.shadowColor = "#ccc";
		context.shadowBlur = shadowBlur+1;
		context.shadowOffsetX = 0;
		context.shadowOffsetY = 0;
		context.beginPath();
		context.arc(x, y, radius, 0.5*Math.PI, 0.49*Math.PI, false);
		context.stroke();
		
		
		var linear = context.createLinearGradient(10,0,360,360); 
		linear.addColorStop(0,'#aaa'); 
		linear.addColorStop(0.5,'#f44444'); 
		linear.addColorStop(1,'red');
		
		if(ii>=3){
			ii=1;
		}else{
			ii+=1;
		}
		
		var dian="";
		for (var i = 0; i < ii; i++) {
			dian+=".";
		}
		
		context.beginPath();
		context.fillStyle = "#666666";
		context.font = "bold 40px Helvetica";
		context.fillText("数据上传中"+dian,  width/2-120, height/2+10);
		context.closePath();
		
		context.restore();

	}
}

var ii=1;


var chartMarginTop = 10;
var chartMarginBottom = 45;
var chartMarginLeft = 80;
var chartMarginRight = 80;


var timeType = 0;
var clickableList = new Array(4);
var valueList = new Array(4);
var clickRange = 50;

//画折线图
function drawChart(jsonData,index) {
    var clickables;
    var values;
    var chartArray=jsonData.chartArray[index];
    var canvasId = "canvasBox_0";
    document.getElementById("timeType").value=chartArray.timeType;//时间类型 周、天
    document.getElementById("title_top").innerHTML=chartArray.timeText;//头部标题
    if(chartArray.timeType==1){
		document.getElementById("head_text").innerHTML="天";//头部右侧
	}else{
		document.getElementById("head_text").innerHTML="周";//头部右侧
	}
    if(chartArray.timeText=="今天"||chartArray.timeText=="本周"){
		document.getElementById("btn_forward").style.display="none";
	}else{
		document.getElementById("btn_forward").style.display="block";
	}
//    if(chartArray.isLast==0){
//		document.getElementById("btn_forward").style.display="none";
//	}else{
//		document.getElementById("btn_forward").style.display="block";
//	}
    if(chartArray.isFirst==0){
    	document.getElementById("btn_back").style.display="none";
    }else{
    	document.getElementById("btn_back").style.display="block";
    }
    document.getElementById("startTime").value=chartArray.startTime;//开始时间
   
    //var timeTextId = "timeText_" + jsonData.stepDate;
    // 页面中部时间文字
    //document.getElementById("floatTimeText").innerHTML = jsonData.timeText;

    clickables = new Array();
    values = new Array();

    var canvas = document.getElementById(canvasId);
    if (canvas == null) {
        return false;
    }
    canvas.width = window.innerWidth * 2;
//    canvas.height = window.innerHeight * 0.60;
    var ah = document.getElementById("btn_top_left").offsetHeight;
    var bh = document.getElementById("container_circle").offsetHeight;
    var ch = document.getElementById("container_circle_item").offsetHeight;
//    alert(ah+bh+ch);
//    alert(document.documentElement.clientHeight);
    if(document.documentElement.clientHeight<320){
    	canvas.height = window.innerHeight * 0.60;
    }else{
    	canvas.height =document.documentElement.clientHeight*2-(ah+bh+ch+15)*2;
    }
    
    var name=navigator.platform;
    if(window.orientation==90 || window.orientation==-90){
//    	if(name.substring(0, 5)=="Linux"){
//    		canvas.width = window.innerWidth * 2;
//            canvas.height = window.innerHeight * 0.60;
//    	}else{
    		canvas.height = window.innerWidth * 0.9;
    		canvas.width = window.innerWidth*2;
//    	}
		
 	}
    if(window.orientation==0 || window.orientation==180){
//    	if(name.substring(0, 5)=="Linux"){
//    		canvas.height = window.innerWidth * 0.9;
//    		canvas.width = window.innerWidth*2;
//    	}else{
    		canvas.width = window.innerWidth * 2;
//    		canvas.height =document.documentElement.clientHeight*2-(ah+bh+ch+15)*2;
    		if(document.documentElement.clientHeight<460){
    	    	canvas.height = window.innerHeight * 0.60;
    	    }else{
    	    	canvas.height =document.documentElement.clientHeight*2-(ah+bh+ch+15)*2;
    	    }
//    	}
    	
	}
    
    var context = canvas.getContext("2d");
    var width = canvas.width;
    var height = canvas.height;
    var xLabels = chartArray.xLabels;
    var yLabels = chartArray.yLabels;


    // 网格
    context.strokeStyle = "#aaa";
    context.lineWidth = 1;
    context.font = "20px sans-serif";
    context.fillStyle = "#afb0b1";
    context.textAlign = "center";
    context.textBaseline = "top";

    var xWidth = width - chartMarginLeft - chartMarginRight;
    var yHeight = height - chartMarginTop - chartMarginBottom;
    var xSpace = xWidth / (xLabels.length - 1);
    var ySpace = yHeight / (yLabels.length - 1);
    var x, y;

    // 竖线
    for (var i = 0; i < xLabels.length; i++) {
        x = chartMarginLeft + xSpace * i;
        y = chartMarginTop;
        if (xLabels[i].indexOf("月") >= 0) {
            context.font = "bold 21px sans-serif";
        } else {
            context.font = "20px sans-serif";
        }
        if(chartArray.timeType==0)
        	context.fillText(xLabels[i], x, y + yHeight +10);
        else
        	context.fillText(xLabels[i], x, y + yHeight +10);
    }

    context.font = "20px sans-serif";

    // 曲线
    context.lineWidth = 4;
    x = y = 0;
    var radius = 8;
    var centerX, centerY;
    var chartData = chartArray.chartData;
    var xMin = chartArray.xMin;
    var xMax = chartArray.xMax;
    var yMin = chartArray.yMin * 1.0;
    var yMax = chartArray.yMax * 1.0;
    var valueKey = "values";
    context.strokeStyle = "#f7bb6f";
    
    for (var i = 0; i < chartData.length; i++) {
        var item = chartData[i];
        //周
        if(chartArray.timeType==0){
	        
	        context.lineWidth = 10;
            context.beginPath();
            x = chartMarginLeft + (item["time"] - xMin) / (xMax - xMin) * xWidth;
            y = chartMarginTop + yHeight - (item[valueKey][0] - yMin) / (yMax - yMin) * yHeight;
            centerX = x + 0;
            centerY = y + 0;
            context.lineTo(centerX, centerY);
            centerY=chartMarginTop+yHeight;
            context.lineTo(centerX, centerY);
            context.stroke();
            //context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
            context.closePath();
        }
        // 日
        if(chartArray.timeType==1){
	        if (item["visible"]) {
	        	context.lineWidth = 10;
	            context.beginPath();
	            x = chartMarginLeft + (item["time"] - xMin) / (xMax - xMin) * xWidth;
	            y = chartMarginTop + yHeight - (item[valueKey][0] - yMin) / (yMax - yMin) * yHeight;
	            centerX = x + 0;
	            centerY = y + 0;
	            context.lineTo(centerX, centerY);
	            centerY=chartMarginTop+yHeight;
	            context.lineTo(centerX, centerY);
	            context.stroke();
	            context.closePath();

	        }
        }
    }
    var isNoValues=true;
    for (var i = 0; i < chartData.length; i++) {
        var item = chartData[i];
        if(item["values"]>0){
        	isNoValues=false;
        	break;
        }
    }
    if(isNoValues){
    	chartData=[];
    }
    
    if(chartData.length==0){
    	 
    	x = chartMarginLeft+xWidth/2;
        y =  yHeight/2;
        context.fillStyle = "#666";
        context.font = "32px sans-serif";
        context.fillText("无运动记录", x, y);
    }
    

//    alert(circleData.pedometerGoal+"  "+chartArray.pedometerGoal);
	if(chartArray.timeType==0&&chartArray.pedometerGoal>0&&chartData.length>0){
	     xMin = chartArray.xMin;
	    xMax = chartArray.xMax;
	    yMin = chartArray.yMin * 1.0;
	    yMax = chartArray.yMax * 1.0;
	    valueKey = "pedometerGoal";
	    context.lineWidth = 2;
	    context.strokeStyle = "#f7882d";
	    var pg=0;
	    if(index==0){
	    	pg=chartArray.pedometerGoal;
	    }else if(index==1){
	    	var height1 = document.getElementById("hidden_memberHeight").value/100;
			pg = height1*0.4*chartArray.pedometerGoal/1000;
		}else if(index==2){
			var weight = document.getElementById("hidden_memberWeight").value;
			pg = 0.0004*weight*chartArray.pedometerGoal;
		}
		x = chartMarginLeft + (xMin - xMin) / (xMax - xMin) * xWidth;
        y = chartMarginTop + yHeight - ( pg- yMin) / (yMax - yMin) * yHeight;
        context.fillStyle = "#f7882d";
        context.font = "25px sans-serif";
        
        moveToFunction =CanvasRenderingContext2D.prototype.moveTo;  
    	CanvasRenderingContext2D.prototype.lastMoveToLocation= {};  
    	CanvasRenderingContext2D.prototype.moveToa =function (x, y) {  
    	   moveToFunction.apply(context, [x,y]);  
    	   this.lastMoveToLocation.x = x;  
    	   this.lastMoveToLocation.y = y;  
    	};  
    	CanvasRenderingContext2D.prototype.dashedLineTo =  
    	      function (x, y, dashLength) {  
    	   dashLengthdashLength = dashLength === undefined ? 5 :dashLength;  
    	   var startX = this.lastMoveToLocation.x;  
    	   var startY = this.lastMoveToLocation.y;  
    	   var deltaX = x - startX;  
    	   var deltaY = y - startY;  
    	   var numDashes = Math.floor(Math.sqrt(deltaX *deltaX + deltaY * deltaY) /dashLength);  

    	   for (var i=0; i < numDashes; ++i) {  
    	      this[ i % 2 == 0 ? 'moveTo' : 'lineTo' ]  
    	         (startX + (deltaX / numDashes) * i,  
    	            startY + (deltaY / numDashes) * i);  
    	   } 
    	   this.moveToa(x, y); 

    	   
    	};  
    	context.beginPath();
    	var startY = chartMarginTop + yHeight - (pg - yMin) / (yMax - yMin) * yHeight;;
    	var endX = chartMarginLeft + xWidth;
    	var endY = chartMarginTop + yHeight - (pg - yMin) / (yMax - yMin) * yHeight;;
    	context.dashedLineTo(chartMarginLeft, startY,10);  
    	context.dashedLineTo(endX,endY,10);
    	context.stroke(); 
    	context.closePath();
        
	}
    valueList[0] = values;
    clickableList[0] = clickables;
    
    var pop = document.getElementById("popupArrow");
    var popLine = document.getElementById("popupLine");
    pop.style.visibility = "hidden";
    popLine.style.visibility = "hidden";
}


function chartEvent(e) {
    document.getElementById("container_chart").blur();
    
    var pop = document.getElementById("popupArrow");
    var popLine = document.getElementById("popupLine");
    var container=document.getElementById("container");
    container.onclick=function (event){
    	if (event.srcElement.id.toString().indexOf("canvasBox_") < 0) {
	            pop.style.visibility = "hidden";
	            popLine.style.visibility = "hidden";
	            return;
		}
    };
    if (e.srcElement.id.toString().indexOf("canvasBox_") < 0) {
        pop.style.visibility = "hidden";
        popLine.style.visibility = "hidden";
        return;
    }
    var offsetTop = document.getElementById(e.srcElement.id).offsetTop;
    var canvasHeight = document.getElementById(e.srcElement.id).offsetHeight;
    var x2 = e.x * 2;
    var y2 = (e.y - offsetTop) * 2;
    for (var i = 0; i < clickableList[timeType].length; i++) {
        var cX = clickableList[timeType][i][0];
        var cY = clickableList[timeType][i][1];
        if ((x2 >= cX - clickRange && x2 <= cX + clickRange)) {
            document.getElementById("popupArrow").innerHTML = valueList[timeType][i] + "";
            var popX = cX / 2;// - pop.offsetWidth / 2
            var popY =  offsetTop + chartMarginTop ;

            popLine.style.visibility = "visible";
            popLine.style.top = (offsetTop + chartMarginTop/2) + "px";
            popLine.style.left = cX/2 - popLine.offsetWidth/2 + "px";
            popLine.style.height = canvasHeight - chartMarginTop/2 - chartMarginBottom/2 + "px";

            pop.style.background='url('+ctx+'/v2/img/pop_right.png) no-repeat';
            if (popX < chartMarginLeft) {//左边
                popX = cX/2;
                pop.style.background='url('+ctx+'/v2/img/pop_right.png) no-repeat';
            } else if (popX > window.innerWidth - chartMarginRight - pop.offsetWidth/2) {//右边
            	popX = cX / 2 - pop.offsetWidth;
                pop.style.background='url('+ctx+'/v2/img/pop_left.png) no-repeat';
            }
//            if (popY < offsetTop) {
//                popY = cY / 2 + offsetTop - chartMarginTop;
//            }

            pop.style.visibility = "visible";
            pop.style.top = popY + "px";
            pop.style.left = popX + "px";
            e.preventDefault();
            return;
        }
    }
    e.preventDefault();
    pop.style.visibility = "hidden";
    popLine.style.visibility = "hidden";
    
}

Date.prototype.format = function(format) {
    /*
     * format="yyyy-MM-dd hh:mm:ss";
     */
    var o = {
        "M+" : this.getMonth() + 1,
        "d+" : this.getDate(),
        "h+" : this.getHours(),
        "m+" : this.getMinutes(),
        "s+" : this.getSeconds(),
        "q+" : Math.floor((this.getMonth() + 3) / 3),
        "S" : this.getMilliseconds()
    };
    if (/(y+)/.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4- RegExp.$1.length));
        }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)){
            format = format.replace(RegExp.$1, RegExp.$1.length == 1? o[k]:("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
    
};


//圆环json数据
var circleData;
//图表json数据
var chartData;
//圆环动态显示
var timerId;
var flag = 0;
var flagMax = 10;

function loadData(){isload=true;
	ajaxLoadPedometerRecord2();
}

var load=null;
var ii=0;
var oldDate=null;
var oldStep=0;
var oldCalories=0;
var oldDistance=0;
var isupdate=1;
var isupdate2=1;
var isload=true;
//初始化数据
function initData(jsonData){
	var step = 0;
	var distance=0;
	var calories=0;
	var pedometerGoal = 0;
	console.log("initData");
	try{
		//document.getElementById("canvas_pedometer2").style.display="none";
		//-MM-dd hh:mm:ss
		var lastDatey=new Date(jsonData.lastRecordDate.time);
		var reloadTime=jsonData.reloadTime;
//		if(load!=null){
//			clearInterval(load);
//			load=setInterval("loadData()", reloadTime);
//		}else{
//			load=setInterval("loadData()", reloadTime);
//		}
		
		if(oldDate==null){
			oldDate=lastDatey;
			oldStep=jsonData.step;
			oldCalories=jsonData.calories;
			oldDistance=jsonData.distance;
		}else{
			isupdate=oldDate.getTime()-lastDatey.getTime();  //时间差的毫秒数
			if(oldStep!=jsonData.step||oldCalories!=jsonData.calories||oldDistance!=jsonData.distance){
				isupdate=1;
			}else{
				isupdate=0;
			}
			oldDate=lastDatey;
			oldStep=jsonData.step;
			oldCalories=jsonData.calories;
			oldDistance=jsonData.distance;
		}	
		
		step = jsonData.step;
		if(jsonData.distance=="undefined")
			distance=0;
		else
			distance=jsonData.distance/1000;
		if(jsonData.calories=="undefined")
			calories=0;
		else
			calories=jsonData.calories;
		
		if(jsonData.timeType==0){
			pedometerGoal = jsonData.pedometerGoal*7;
		}else{
			pedometerGoal = jsonData.pedometerGoal;
		}
		
	}catch(err){
		step = 0;
		pedometerGoal = 0;
	}
	if(step>9999999){
		document.getElementById("data_pedometer").style.fontSize="0.75em";
		document.getElementById("data_pedometer").style.top="93px";
	}else if(step>999999){
		document.getElementById("data_pedometer").style.fontSize="0.85em";
		document.getElementById("data_pedometer").style.top="90px";
	}else if(step>99999){
		document.getElementById("data_pedometer").style.fontSize="1em";
		document.getElementById("data_pedometer").style.top="85px";
	}
	if(step==0){
		document.getElementById("data_text").style.display="none";
		document.getElementById("data_pedometer").style.display="none";
		document.getElementById("data_stepPercent").style.display="none";
		document.getElementById("data_none").style.display="block";
	}else{
		document.getElementById("data_text").style.display="block";
		document.getElementById("data_pedometer").style.display="block";
		document.getElementById("data_stepPercent").style.display="block";
		document.getElementById("data_none").style.display="none";
	}
	
	//--
	if(itemId=="container_circle_item_left"){
		var stepPercent=0;
		if(pedometerGoal>0&&timeType==1)
			stepPercent=step/pedometerGoal*100;
		else if(pedometerGoal>0)
			stepPercent=step/pedometerGoal*100;
		document.getElementById("data_text").innerHTML="步数";//圆环文字
		document.getElementById("data_pedometer").innerHTML=step;//圆环数量
		if(stepPercent==0){
			document.getElementById("data_stepPercent").innerHTML=stepPercent+"%";//圆环百分比
		}else{
			var str=parseFloat(stepPercent).toFixed(1);
			var point=str.indexOf(".");
			var str1=str.substring(point+1, str.length);
			if(str1=="0"){
				str=str.substring(0,point);
			}
			document.getElementById("data_stepPercent").innerHTML=str+"%";//圆环百分比
		}
//		flag = 0;
		if(stepPercent<1&&stepPercent>0)
			stepPercent=1;
		flagMax = stepPercent;
//		if(timerId==null)
//			timerId = setInterval("Change()",1);
	}else if(itemId=="container_circle_item_center"){
		var distancePercent=0;
		var height = document.getElementById("hidden_memberHeight").value/100;
		if(pedometerGoal>0)
			distancePercent = distance/(height*0.4*pedometerGoal/1000)*100;
		document.getElementById("data_text").innerHTML="公里";//圆环文字
		if(distance==0){
			document.getElementById("data_pedometer").innerHTML=distance;//圆环数量
		}else{
			var str=parseFloat(distance).toFixed(2);
			document.getElementById("data_pedometer").innerHTML=str;//圆环数量
		}
		if(distancePercent==0){
			document.getElementById("data_stepPercent").innerHTML=distancePercent+"%";//圆环百分比
		}else{
			var str=parseFloat(distancePercent).toFixed(1);
			var point=str.indexOf(".");
			var str1=str.substring(point+1, str.length);
			if(str1=="0"){
				str=str.substring(0,point);
			}
			document.getElementById("data_stepPercent").innerHTML=str+"%";//圆环百分比
		}
//		flag = 0;
		if(distancePercent<1&&distancePercent>0)
			distancePercent=1;
		flagMax = distancePercent;
//		if(timerId==null)
//			timerId = setInterval("Change()",1);
	}else if(itemId=="container_circle_item_right"){
		var caloriesPercent=0;
		var weight = document.getElementById("hidden_memberWeight").value;
		if(pedometerGoal>0&&timeType==1)
			caloriesPercent=calories/(0.0004*weight*pedometerGoal)*100;
		else if(pedometerGoal>0)
			caloriesPercent=calories/(0.0004*weight*pedometerGoal)*100;
		document.getElementById("data_text").innerHTML="大卡";//圆环文字
		if(calories==0){
			document.getElementById("data_pedometer").innerHTML=calories;//圆环数量
		}else{
			var str=parseFloat(calories).toFixed(1);
			var point=str.indexOf(".");
			var str1=str.substring(point+1, str.length);
			if(str1=="0"){
				str=str.substring(0,point);
			}
			document.getElementById("data_pedometer").innerHTML=str;//圆环数量
		}
		if(caloriesPercent==0){
			document.getElementById("data_stepPercent").innerHTML=caloriesPercent+"%";//圆环百分比
		}else{
			var str=parseFloat(caloriesPercent).toFixed(1);
			var point=str.indexOf(".");
			var str1=str.substring(point+1, str.length);
			if(str1=="0"){
				str=str.substring(0,point);
			}
			document.getElementById("data_stepPercent").innerHTML=str+"%";//圆环百分比
		}
//		flag = 0;
		if(caloriesPercent<1&&caloriesPercent>0)
			caloriesPercent=1;
		flagMax = caloriesPercent;
//		if(timerId==null)
//			timerId = setInterval("Change()",1);
	}
	//--
	
//	document.getElementById("data_text").innerHTML="步数";//圆环文字
//	document.getElementById("data_pedometer").innerHTML=step;//圆环数量
//	var stepPercent=0;
//	var timeType=jsonData.timeType;
//	if(pedometerGoal>0&&timeType==1)
//		stepPercent=step/pedometerGoal*100;
//	else if(pedometerGoal>0)
//		stepPercent=step/pedometerGoal*100;
//	if(stepPercent==0){
//		document.getElementById("data_stepPercent").innerHTML=stepPercent+"%";//圆环百分比
//	}else{
//		var str=parseFloat(stepPercent).toFixed(1);
//		var point=str.indexOf(".");
//		var str1=str.substring(point+1, str.length);
//		if(str1=="0"){
//			str=str.substring(0,point);
//		}
//		document.getElementById("data_stepPercent").innerHTML=str+"%";//圆环百分比
//	}
	
	
	document.getElementById("step_value").innerHTML= step;//步数值
	//distance=step*0.4/1000;
	if(distance==0){
		document.getElementById("distance_value").innerHTML=distance;//里程值
	}else{
		var str=parseFloat(distance).toFixed(2);
		var point=str.indexOf(".");
		var str1=str.substring(point+1, str.length);
		if(str1=="0"){
			str=str.substring(0,point);
		}
		document.getElementById("distance_value").innerHTML=str;//里程值
	}
	if(calories==0){
		document.getElementById("calories_value").innerHTML=calories;//卡路里值
	}else{
		var str=parseFloat(calories).toFixed(1);
		var point=str.indexOf(".");
		var str1=str.substring(point+1, str.length);
		if(str1=="0"){
			str=str.substring(0,point);
		}
		document.getElementById("calories_value").innerHTML=str;//卡路里值
	}
	
	
	var circleId = "container_circle_item_";
	var classNme = "";
	if(circleData.step != 0 && circleData.pedometerGoal != 0){
		classNme = "selected";
	}
	for (var i = 0; i < circleTypeIds.length; i++) {
		document.getElementById(circleId + circleTypeIds[i]).className = "";
		if ((circleId + circleTypeIds[i]) == itemId) {
			document.getElementById(circleId + circleTypeIds[i]).className = classNme;
//			changeCircle(itemId);
//			drawChart(chartData,circleData,0);
		}
	}
	
	
	
}

var itemId="container_circle_item_left";

function Change(){
	var i = flag;
	if (i > flagMax) {
		window.clearInterval(timerId);
	}else{
		drawCircle_pedometer("canvas_pedometer",i,1);//画圆
		flag +=1;
	}
}

//切换圆环
var circleTypeIds = [ "left", "center", "right" ];
function changeCircle(circleTypeId){
//	if(circleData=="undefined")
//		return;
	if(timerId!=null)
		window.clearInterval(timerId);
	var circleId = "container_circle_item_";
	var classNme = "";
	try{
		if(circleData.step!="undefined"){
			if(circleData.step != 0 && circleData.pedometerGoal != 0){
				classNme = "selected";
			}
		}
	}catch(err){
		
	}
	for (var i = 0; i < circleTypeIds.length; i++) {
		document.getElementById(circleId + circleTypeIds[i]).className = "";
		if ((circleId + circleTypeIds[i]) == circleTypeId) {
			document.getElementById(circleId + circleTypeIds[i]).className = classNme;
		}
	}
	
	var step = 0;
	var pedometerGoal = 0;
	var timeType=0;
	var distance=0;
	var calories=0;
	try{
		timeType=circleData.timeType;
		if(circleData.step=="undefined")
			step=0;
		else
			step = circleData.step;
		if(circleData.distance=="undefined")
			distance=0;
		else
			distance=circleData.distance/1000;
		if(circleData.calories=="undefined")
			calories=0;
		else
			calories=circleData.calories;
		if(timeType==0)
			pedometerGoal = circleData.pedometerGoal*7;
		else
			pedometerGoal = circleData.pedometerGoal;
	}catch(err){
//		alert(err);
	}
	if(circleTypeId=="container_circle_item_left"){
		var stepPercent=0;
		
		if(pedometerGoal>0&&timeType==1)
			stepPercent=step/pedometerGoal*100;
		else if(pedometerGoal>0)
			stepPercent=step/pedometerGoal*100;
		document.getElementById("data_text").innerHTML="步数";//圆环文字
		document.getElementById("data_pedometer").innerHTML=step;//圆环数量
		if(stepPercent==0){
			document.getElementById("data_stepPercent").innerHTML=stepPercent+"%";//圆环百分比
		}else{
			var str=parseFloat(stepPercent).toFixed(1);
			var point=str.indexOf(".");
			var str1=str.substring(point+1, str.length);
			if(str1=="0"){
				str=str.substring(0,point);
			}
			document.getElementById("data_stepPercent").innerHTML=str+"%";//圆环百分比
		}
		flag = 0;
		if(stepPercent<1&&stepPercent>0)
			stepPercent=1;
		flagMax = stepPercent;
//		alert(flagMax);
		timerId = setInterval("Change()",1);
		drawChart(chartData,0);
	}else if(circleTypeId=="container_circle_item_center"){
		//var distance=step*0.4/1000;
		var distancePercent=0;
		var height = document.getElementById("hidden_memberHeight").value/100;
		if(pedometerGoal>0)
			distancePercent = distance/(height*0.4*pedometerGoal/1000)*100;
//		if(pedometerGoal>0&&timeType==1)
//			distancePercent=distance/(pedometerGoal*0.4/1000)*100;
//		else if(pedometerGoal>0)
//			distancePercent=distance/(pedometerGoal*0.4/1000)*100;
		document.getElementById("data_text").innerHTML="公里";//圆环文字
		if(distance==0){
			document.getElementById("data_pedometer").innerHTML=distance;//圆环数量
		}else{
			var str=parseFloat(distance).toFixed(2);
			var point=str.indexOf(".");
			var str1=str.substring(point+1, str.length);
			if(str1=="0"){
				str=str.substring(0,point);
			}
			document.getElementById("data_pedometer").innerHTML=str;//圆环数量
		}
		if(distancePercent==0){
			document.getElementById("data_stepPercent").innerHTML=distancePercent+"%";//圆环百分比
		}else{
			var str=parseFloat(distancePercent).toFixed(1);
			var point=str.indexOf(".");
			var str1=str.substring(point+1, str.length);
			if(str1=="0"){
				str=str.substring(0,point);
			}
			document.getElementById("data_stepPercent").innerHTML=str+"%";//圆环百分比
		}
		flag = 0;
		if(distancePercent<1&&distancePercent>0)
			distancePercent=1;
		flagMax = distancePercent;
		timerId = setInterval("Change()",1);
		drawChart(chartData,1);
	}else if(circleTypeId=="container_circle_item_right"){
		//var calories=step/30;
		var caloriesPercent=0;
		var weight = document.getElementById("hidden_memberWeight").value;
		if(pedometerGoal>0&&timeType==1)
			caloriesPercent=calories/(0.0004*weight*pedometerGoal)*100;
		else if(pedometerGoal>0)
			caloriesPercent=calories/(0.0004*weight*pedometerGoal)*100;
//		if(pedometerGoal>0&&timeType==1)
//			caloriesPercent=calories/(pedometerGoal/30)*100;
//		else if(pedometerGoal>0)
//			caloriesPercent=calories/(pedometerGoal/30)*100;
		document.getElementById("data_text").innerHTML="大卡";//圆环文字
		if(calories==0){
			document.getElementById("data_pedometer").innerHTML=calories;//圆环数量
		}else{
			var str=parseFloat(calories).toFixed(1);
			var point=str.indexOf(".");
			var str1=str.substring(point+1, str.length);
			if(str1=="0"){
				str=str.substring(0,point);
			}
			document.getElementById("data_pedometer").innerHTML=str;//圆环数量
		}
		if(caloriesPercent==0){
			document.getElementById("data_stepPercent").innerHTML=caloriesPercent+"%";//圆环百分比
		}else{
			var str=parseFloat(caloriesPercent).toFixed(1);
			var point=str.indexOf(".");
			var str1=str.substring(point+1, str.length);
			if(str1=="0"){
				str=str.substring(0,point);
			}
			document.getElementById("data_stepPercent").innerHTML=str+"%";//圆环百分比
		}
		flag = 0;
		if(caloriesPercent<1&&caloriesPercent>0)
			caloriesPercent=1;
		flagMax = caloriesPercent;
		timerId = setInterval("Change()",1);
		drawChart(chartData,2);
	}
}


//添加目标步数
function add_pedometerGoal(){
	isload=true;
	isupdate2=1;
	if(se==0){
		return;
	}
	showBg();
	var openId=document.getElementById("openId").value;
	var token=document.getElementById("token").value;
	var memberId = document.getElementById("hidden_memberId").value;
	var pedometerGoal=document.getElementById("alert_pedometerGoal_value").innerHTML;
	if(pedometerGoal<0){
		alert("目标步数不能小于0");
		return;
	}
	var xhr = createXmlHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				var json=xhr.responseText;
				if(json=="900001"){
					to(json);
					return;
				}
				hiddenBg();
				removeMybg();
				if(document.getElementById("timeType").value=="0"){
					if(document.getElementById("title_top").innerHTML=="本周"){
						ajaxLoadPedometerRecord();
					}
					else{
						isupdate2=0;
						return;
					}
				}
				ajaxLoadPedometerRecord();
			} else {
//				alert(err);
			}
		}
	};
	var url = ctx+"/wechat/ajax_member_edit";
	xhr.open("post", url + "?memberId=" + memberId+"&&stepGoal="+pedometerGoal+"&&action_member=addGoal"+"&&openId="+openId+"&&token="+token+"&mathNum="+Math.random(), true);
	xhr.send();
}
//读取目标步数
function load_pedometerGoal(){
	showBg();
	//showAjaxLoader();
	var memberId = document.getElementById("hidden_memberId").value;
	var openId=document.getElementById("openId").value;
	var token=document.getElementById("token").value;
	var xhr = createXmlHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				var json=xhr.responseText;
				if(json=="900001"){
					to(json);
					return;
				}
				
				if(json.length>0){
					var jsonData = eval( "(" + json + ")" );//转换后的JSON对象
					var step = document.getElementById("alert_pedometerGoal_value").innerHTML=jsonData.pedometerGoal;
					value_change();
					alertWin(step);
					hiddenBg();
				} else {
					httpTimeOut();
				}
			}
		}
	};
	var url = "/api/ajax/editMemberData";
	xhr.open("post", url + "?memberId=" + memberId+"&&action_member=actionLoad"+"&&openId="+openId+"&&token="+token+"&mathNum="+Math.random(), true);
	xhr.send();
}

var isRequest=false;

//加载圆环数据
function ajaxLoadPedometerRecord() {
	if(isRequest==true){
		return;
	}
	isRequest=true;
	var memberId = document.getElementById("hidden_memberId").value;
	var startTime = document.getElementById("startTime").value;
	var timeType = document.getElementById("timeType").value;
	var openId=document.getElementById("openId").value;
	var token=document.getElementById("token").value;
	var xhr = createXmlHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				isRequest=false;
				var json = xhr.responseText;
				if(json=="900001"){
					to(json);
					return;
				}
				
				if(json.length>0){
					var jsonData = eval( "(" + json + ")" );//转换后的JSON对象
					
					//alert(jsonData.mathNum+" "+mathNum)
					//if(jsonData.mathNum!=mathNum)return;					
		
					circleData=jsonData;
					initData(jsonData);

					hiddenBg();
					chartData=jsonData;
					

					changeCircle(itemId);
					/*
					if(isupdate!=0||isupdate2!=0){						
						isupdate2=0;
						changeCircle(itemId);
					}
					*/
					
				}else{
					httpTimeOut();
				}
			}
		}
	};
	var url = "/api/ajax/getSportDataOfPage";
	mathNum=Math.random();
	xhr.open("post", url + "?check=circle&&memberId=" + memberId+"&&startTime="+startTime+"&&timeType="+timeType+"&&openId="+openId+"&&token="+token+"&mathNum="+mathNum, true);
	xhr.send();
}
var mathNum;

//加载圆环数据
function ajaxLoadPedometerRecord2() {
	if(isload==false)
		return;
	var memberId = document.getElementById("hidden_memberId").value;
	var startTime = document.getElementById("startTime").value;
	var timeType = document.getElementById("timeType").value;
	var openId=document.getElementById("openId").value;
	var token=document.getElementById("token").value;
	var xhr2 = createXmlHttpRequest();
	xhr2.onreadystatechange = function() {
		
		if (xhr2.readyState == 4) {
			if (xhr2.status == 200) {
				var json = xhr2.responseText;
				if(json=="900001"){
					to(json);
					return;
				}
				if(isload==false)
					return;
				if(json.length>0){
					var jsonData = eval( "(" + json + ")" );//转换后的JSON对象
					circleData=jsonData;
					initData(jsonData);
					hiddenBg();
					chartData=jsonData;
					if(isupdate!=0||isupdate2!=0){
						isupdate2=0;
						changeCircle(itemId);
					}

				}else{
					httpTimeOut();
				}
			}
		}
	};
	var url = "/api/ajax/getSportDataOfPage";
	xhr2.open("post", url + "?check=circle&&memberId=" + memberId+"&&startTime="+startTime+"&&timeType="+timeType+"&&openId="+openId+"&&token="+token+"&mathNum="+Math.random(), true);
	xhr2.send();
}

//切换周、天
function ajax_change_pedometer(){
	if(timerId!=null)
		window.clearInterval(timerId);
	isload=false;
	if(isRequest==true){
		return;
	}
	isRequest=true;
//	itemId="container_circle_item_left";
	var memberId = document.getElementById("hidden_memberId").value;
	var timeType = document.getElementById("timeType").value;
	var openId=document.getElementById("openId").value;
	var token=document.getElementById("token").value;
	if(timeType==1){
		timeType=0;
		document.getElementById("timeType").value="0";
	}else{
		timeType=1;
		document.getElementById("timeType").value="1";
	}
	var xhr = createXmlHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				isRequest=false;
				isload=false;
				var json = xhr.responseText;
				if(json=="900001"){
					to(json);
					return;
				}
				if(json.length>0){
					var jsonData = eval( "(" + json + ")" );//转换后的JSON对象
//					if(jsonData.mathNum!=mathNum){
////						alert(1)
//						return;
//					}
					circleData=jsonData;
					initData(jsonData);

					hiddenBg();
					chartData=jsonData;
					changeCircle(itemId);
				}else{
					httpTimeOut();
				}
			}
		}
	};

	var url = "/api/ajax/getSportDataOfPage";
	mathNum=Math.random();
	xhr.open("post", url + "?startTime=&&status=&&timeType="+timeType+"&&init=dw&&check=circle&&memberId=" + memberId+"&&openId="+openId+"&&token="+token+"&mathNum="+mathNum, true);
	xhr.send();
}

//后退
function ajax_back_pedometer(){
	if(isRequest==true){
		return;
	}
	isRequest=true;
	isload=false;
	if(timerId!=null)
		window.clearInterval(timerId);
//	itemId="container_circle_item_left";
	var startTime = document.getElementById("startTime").value;
	var memberId = document.getElementById("hidden_memberId").value;
	var timeType = document.getElementById("timeType").value;
	var openId=document.getElementById("openId").value;
	var token=document.getElementById("token").value;
	var xhr = createXmlHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				isRequest=false;
				isload=false;
				var json = xhr.responseText;
				if(json=="900001"){
					to(json);
					return;
				}
				console.log(json);
				if(json.length>0){
					var jsonData = eval( "(" + json + ")" );//转换后的JSON对象
					if(jsonData.mathNum!=mathNum){
//						alert(1)
						return;
					}
					circleData=jsonData;
					initData(jsonData);

					hiddenBg();
					chartData=jsonData;
					changeCircle(itemId);
				}else {
					httpTimeOut();
				}
			} 
		}
	};
	var url = "/api/ajax/getSportDataOfPage";
	mathNum=Math.random();
	xhr.open("post", url + "?startTime="+startTime+"&&status=back&&timeType="+timeType+"&&check=circle&&memberId=" + memberId+"&&openId="+openId+"&&token="+token+"&mathNum="+mathNum, true);
	xhr.send();
}

//前进
function ajax_forward_pedometer(){
	if(isRequest==true){
		return;
	}
	isRequest=true;
	if(timerId!=null)
		window.clearInterval(timerId);
	isload=false;
//	itemId="container_circle_item_left";
	var startTime = document.getElementById("startTime").value;
	var memberId = document.getElementById("hidden_memberId").value;
	var timeType = document.getElementById("timeType").value;
	var openId=document.getElementById("openId").value;
	var token=document.getElementById("token").value;
	var xhr = createXmlHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				isRequest=false;
				isload=false;
				var json = xhr.responseText;
				if(json=="900001"){
					to(json);
					return;
				}
				if(json.length>0){
					var jsonData = eval( "(" + json + ")" );//转换后的JSON对象
					if(jsonData.mathNum!=mathNum){
						return;
					}
					circleData=jsonData;
					initData(jsonData);

					hiddenBg();
					chartData=jsonData;
					changeCircle(itemId);
				}else {
					httpTimeOut();
				}
				
			} 
		}
	};
	var url = "/api/ajax/getSportDataOfPage";
	mathNum=Math.random();
	xhr.open("post", url + "?startTime="+startTime+"&&status=forward&&timeType="+timeType+"&&check=circle&&memberId=" + memberId+"&&openId="+openId+"&&token="+token+"&mathNum="+mathNum, true);
	xhr.send();
}



var cdef={"calories":0,"distance":0,"pedometerGoal":0,"step":0,"stepDate":"本周","stepPercent":"0%"};
var def={"chartArray":[{"birthday":0,"boy":false,"chartData":[],"startTime":"","timeText":"本周","timeType":0,"xLabels":["一","二","三","四","五","六","日"],"xMax":1395590399434,"xMin":1394985600434,"yLabels":["0","1982","3964","5946","7928","9910"],"yLabels_right":[],"yMax":9911,"yMax_right":0,"yMin":0,"yMin_right":0}]};



function init(){
	var container_chart=document.getElementById("container_chart");
	var title_top=document.getElementById("title_top");
	var container_circle=document.getElementById("container_circle");
	var container_circle_item=document.getElementById("container_circle_item");
	var m=title_top.offsetHeight+container_circle.offsetHeight+container_circle_item.offsetHeight+10;
//	container_chart.style.marginBottom="150px";
	container_chart.style.top=m+"px";
	container_chart.style.width="100%";
//	var ah = document.getElementById("btn_top_left").offsetHeight;
//    var bh = document.getElementById("container_circle").offsetHeight;
//    var ch = document.getElementById("container_circle_item").offsetHeight;
//	container_chart.style.height=document.documentElement.clientHeight-ah-bh-ch+"px";
	showBg();
}

function init_other_onclick(){
	//弹出框
	var c3=document.getElementById("btn_back");
	 c3.addEventListener("click", ajax_back_pedometer, false);
	 var c4=document.getElementById("btn_forward");
	 c4.addEventListener("click", ajax_forward_pedometer, false);
	 var mPlus =document.getElementById("alert_value_plus");
	 mPlus.addEventListener("touchstart",touchStart_alert_value_plus,false);
	 mPlus.addEventListener("touchend",touchEnd_alert_value_plus,false);
	 mPlus.addEventListener("touchmove",touchEnd_alert_value_plus,false);
	 var mReduce =document.getElementById("alert_value_reduce");
	 mReduce.addEventListener("touchstart",touchStart_alert_value_reduce,false);
	 mReduce.addEventListener("touchend",touchEnd_alert_value_reduce,false);
	 mReduce.addEventListener("touchmove",touchEnd_alert_value_reduce,false);

	var mSave=document.getElementById("alert_pedometerGoal_save");
	mSave.addEventListener("click",add_pedometerGoal,false);
	se=1;
	var mClose = document.getElementById("alert_pedometerGoal_close");
	mClose.addEventListener("click",removeMybg,false);
	//var myValue=document.getElementById("alert_pedometerGoal_value");
	//myValue.addEventListener("input",value_change,false);
	
	var message_close=document.getElementById("message-close");
	message_close.addEventListener("click", closeMessage, false);
}

function aaa(){
	alert(1)
}

/**
 * 默认点击事件
 *
 * 通过这里调用相应的函数
 *
 */
function containerDefaultClickEvent() {
	init_other_onclick();
    switch (this.id) {
        case "btn_top_left":    // 左上角按钮（头像）
        	load_pedometerGoal();
            break;
        case "btn_top_right":   // 右上角按钮（添加数据）
        	//showAjaxLoader();
//        	ajax_change_pedometer();
        	ajax_change_pedometer();
            break;
        case "container_circle":    // 圆环
            break;
        case "container_circle_item_left": // 圆环下方数据框3个之1（左边）
        	if(itemId!=this.id){
        		changeCircle(this.id);
        		itemId=this.id;
        	}
            break;
        case "container_circle_item_center": // 圆环下方数据框3个之1（中间）
        	if(itemId!=this.id){
        		changeCircle(this.id);
        		itemId=this.id;
        	}
            break;
        case "container_circle_item_right": // 圆环下方数据框3个之1（右边）
        	if(itemId!=this.id){
        		changeCircle(this.id);
        		itemId=this.id;
        	}
            break;
    }
}
//用在iPhone上的点击事件
function init_iphone_onclick(){
	var c=document.getElementById("container");
	c.addEventListener("touchstart", none, false);
	
	 //头部左右
	 var c1=document.getElementById("btn_top_left");
	 c1.addEventListener("touchstart", load_pedometerGoal, false);
	 var c2=document.getElementById("btn_top_right");
	 c2.addEventListener("touchstart", ajax_change_pedometer, false);
	 //圆环左右
	 var c3=document.getElementById("btn_back");
	 c3.addEventListener("touchstart", ajax_back_pedometer, false);
	 var c4=document.getElementById("btn_forward");
	 c4.addEventListener("touchstart", ajax_forward_pedometer, false);
	 //圆环下方切换
	 var c5=document.getElementById("container_circle_item_left");
	 c5.addEventListener("touchstart", touchStart_container_circle_item_left, false);
	 var c6=document.getElementById("container_circle_item_center");
	 c6.addEventListener("touchstart", touchStart_container_circle_item_center, false);
	 var c7=document.getElementById("container_circle_item_right");
	 c7.addEventListener("touchstart", touchStart_container_circle_item_right, false);
	 //弹出框
	 var mClose = document.getElementById("alert_pedometerGoal_close");
	 mClose.addEventListener("touchstart", see, false);
	 mClose.addEventListener("touchend", removeMybg, false);
	 var mSave=document.getElementById("alert_pedometerGoal_save");
	 mSave.addEventListener("touchstart", see, false);
	 mSave.addEventListener("touchend",add_pedometerGoal,false);
	 var mPlus =document.getElementById("alert_value_plus");
	 mPlus.addEventListener("touchstart",touchStart_alert_value_plus,false);
	 mPlus.addEventListener("touchend",touchEnd_alert_value_plus,false);
	 mPlus.addEventListener("touchmove",touchEnd_alert_value_plus,false);
	 var mReduce =document.getElementById("alert_value_reduce");
	 mReduce.addEventListener("touchstart",touchStart_alert_value_reduce,false);
	 mReduce.addEventListener("touchend",touchEnd_alert_value_reduce,false);
	 mPlus.addEventListener("touchmove",touchEnd_alert_value_reduce,false);
	 //var myValue=document.getElementById("alert_pedometerGoal_value");
	 //myValue.addEventListener("input",value_change,false);
	 var bod =document.getElementById("bod");
	 bod.addEventListener("touchmove",touchMove,false);
	 
	 var message_close=document.getElementById("message-close");
	 message_close.addEventListener("touchstart", closeMessage, false);
}
function touchMove(event) {
	se=0;
}
var se=0;
function see(){
	se=1;
}
function none(){
}
function touchStart_container_circle_item_left(event){
	if(itemId!=this.id){
		changeCircle(this.id);
		itemId=this.id;
	}
}
function touchStart_container_circle_item_center(event){
	if(itemId!=this.id){
		changeCircle(this.id);
		itemId=this.id;
	}
}
function touchStart_container_circle_item_right(event){
	if(itemId!=this.id){
		changeCircle(this.id);
		itemId=this.id;
	}
}
function touchStart_alert_value_plus(event){
	var i=0;
	timer=setInterval(function(){
		i++;
		if(i>50||i==1){
			pedometerGoal_plus();
		}
	},10);
}
function touchEnd_alert_value_plus(event){
	//pedometerGoal_plus();
	pedometerGoal_stop();
}
function touchStart_alert_value_reduce(event){
	var i=0;
	timer=setInterval(function(){
		i++;
		if(i>50||i==1){
			pedometerGoal_reduce();
		}
	},10);
}
function touchEnd_alert_value_reduce(event){
	//pedometerGoal_reduce();
	pedometerGoal_stop();
}
//loader加载背景
function showBg() {
//	showAjaxLoader();
	var mybg = document.createElement("div");
	mybg.setAttribute("id", "loader_Bg");
//	mybg.style.background = "#8E8E8E";
	mybg.style.width = "100%";
	mybg.style.height = document.body.scrollHeight+"px";
	mybg.style.top = "0";
	mybg.style.left = "0";
	mybg.style.zIndex = "0";
	mybg.style.opacity = "0.3";
	mybg.style.position = "absolute";
	mybg.style.overflow="hidden";
	document.body.appendChild(mybg);
	document.body.style.overflow = "hidden";
	mybg.onclick = function() {
		return;
	};
}
function hiddenBg(){
	var bg = document.getElementById("loader_Bg");
	if(bg){
		document.body.removeChild(bg);
	}
	hideAjaxLoader();
}

/**
 * 目标热量消耗=0.0004*体重*目标步数
 * 获取目标热量消耗  千卡（未精确小数）
 */
function getCalories(weight,step){
	return 0.0004*weight*step;
	
	
}
/**
 * 目标距离=身高*0.4*目标步数。身高单位是米，结果单位也是米
 * 获取目标距离 m（未精确小数）
 */
function getTD(height,step){
	return height*0.4*step;;
}

//监听横屏竖屏事件
function banOrientation(){
	if(window.orientation==0 || window.orientation==180){//竖屏
		if(chartData!=null&&circleData!=null){
			if(itemId=="container_circle_item_left"){
				setTimeout('drawChart(chartData,0)', 300);
			}else if(itemId=="container_circle_item_center"){
				setTimeout('drawChart(chartData,1)', 300);
			}else if(itemId=="container_circle_item_right"){
				setTimeout('drawChart(chartData,2)', 300);
			}
			
//			drawChart(chartData,circleData,0);
		}
		
	}
 	if(window.orientation==90 || window.orientation==-90){
 		if(chartData!=null&&circleData!=null){
 			if(itemId=="container_circle_item_left"){
				setTimeout('drawChart(chartData,0)', 300);
			}else if(itemId=="container_circle_item_center"){
				setTimeout('drawChart(chartData,1)', 300);
			}else if(itemId=="container_circle_item_right"){
				setTimeout('drawChart(chartData,2)', 300);
			}
//			drawChart(chartData,circleData,0);
		}
 	}
}
/**
 * 请求超时
 */
function httpTimeOut(){
	hiddenBg();
//	alert("网络超时,请重试");
}

function to(result){
	window.location.href=ctx+"/common/900001.jsp";
}


//关闭页头消息
function closeMessage(){
  var obj = document.getElementById("message");
  if (obj != null){
      obj.style.display = "none";
  }
  document.getElementById("btn_top_right").blur()
}

